using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class EOTDCutscene_Entrance : MonoBehaviour
{
	[SerializeField]
	private int CutsceneIndex;

	[Header("-- Cutscene References --")]
	[SerializeField]
	private PlayerManager Kris;

	[SerializeField]
	private PartyMember SusiePartyMember;

	[SerializeField]
	private Susie_Follower Susie;

	[SerializeField]
	private Animator BackgroundAnimator;

	[Header("Landing from the fall")]
	[SerializeField]
	private Vector3 KrisLandPos;

	[SerializeField]
	private Vector3 SusieLandPos;

	[SerializeField]
	private Vector3 KrisStartPos;

	[SerializeField]
	private Vector3 SusieStartPos;

	[Header("-- Cutscene Audio --")]
	[SerializeField]
	private AudioSource CutsceneSource;

	[SerializeField]
	private AudioClip[] CutsceneSounds;

	private void Start()
	{
		((MonoBehaviour)this).StartCoroutine(SetupCutscene());
	}

	private void Update()
	{
		if (CutsceneIndex != 0)
		{
			CutsceneUpdate();
			Susie.FollowingEnabled = false;
			Kris._PlayerState = PlayerManager.PlayerState.Cutscene;
			DarkworldMenu.Instance.CanOpenMenu = false;
		}
	}

	private void CutsceneUpdate()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		switch (CutsceneIndex)
		{
		case 1:
			((Component)Kris).transform.position = KrisStartPos;
			((Component)Susie).transform.position = SusieStartPos;
			CutsceneSource.PlayOneShot(CutsceneSounds[2]);
			CutsceneIndex = 2;
			break;
		case 2:
			if (((Component)Kris).transform.position != KrisLandPos)
			{
				((Component)Kris).transform.position = Vector3.MoveTowards(((Component)Kris).transform.position, KrisLandPos, 15f * Time.deltaTime);
				Kris._PMove.AnimationOverriden = true;
				Kris._PMove._anim.Play("KrisDarkworld_Fall");
			}
			if (((Component)Susie).transform.position != SusieLandPos)
			{
				((Component)Susie).transform.position = Vector3.MoveTowards(((Component)Susie).transform.position, SusieLandPos, 15f * Time.deltaTime);
				Susie.AnimationOverriden = true;
				Susie.SusieAnimator.Play("SusieDarkworld_Fall");
			}
			if (((Component)Kris).transform.position == KrisLandPos && ((Component)Susie).transform.position == SusieLandPos)
			{
				CutsceneSource.PlayOneShot(CutsceneSounds[0]);
				CutsceneIndex = 3;
				Susie.SusieAnimator.Play("SusieDarkworld_Land");
				Kris._PMove._anim.Play("KrisDarkworld_Land");
				((MonoBehaviour)this).StartCoroutine(DelayBeforeBackgroundReveal());
			}
			break;
		}
	}

	private IEnumerator SetupCutscene()
	{
		yield return null;
		SceneManager.LoadScene(10);
	}

	private IEnumerator DelayBeforeBackgroundReveal()
	{
		yield return (object)new WaitForSeconds(1.5f);
		BackgroundAnimator.Play("EOTD_CastletownEntrance_FadeIn");
		CutsceneSource.PlayOneShot(CutsceneSounds[1]);
		yield return (object)new WaitForSeconds(1f);
		CutsceneIndex = 0;
		Kris._PlayerState = PlayerManager.PlayerState.Game;
		Kris.ResetToGameState();
		Susie.FollowingEnabled = true;
		Susie.AnimationOverriden = false;
		Kris._PMove.AnimationOverriden = false;
		Susie.SusieAnimator.Play("Idle");
		Kris._PMove._anim.Play("DARKWORLD_KRIS_IDLE");
		DarkworldMenu.Instance.CanOpenMenu = true;
		((Behaviour)((Component)Kris._PMove).GetComponent<Collider2D>()).enabled = true;
		Susie.RotateSusieToDirection(new Vector2(1f, 0f));
		Kris._PMove.RotatePlayerAnim(new Vector2(0f, -1f));
	}
}
